package com.initialize.appapi.controller;

import com.baomidou.mybatisplus.extension.api.R;
import com.initialize.pub.dao.BingImgDAO;
import com.initialize.pub.mybatis.plus.entity.BingImg;
import com.initialize.pub.mybatis.plus.mapper.BingImgMapper;
import com.initialize.pub.mybatis.plus.service.impl.BingImgServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: jane
 * Date: 2020/3/12
 * Time: 6:38 下午
 * Description:
 */
@Api(tags = "杂类API")
@RestController
@CrossOrigin
@RequestMapping(value = "/tool")
public class MiscellaneousController {


    final
    BingImgServiceImpl BingImgServiceImpl;

    final
    BingImgMapper bingImgMapper;

    final
    BingImgDAO bingImgDAO;

    public MiscellaneousController(BingImgServiceImpl BingImgServiceImpl, BingImgMapper bingImgMapper, BingImgDAO bingImgDAO) {
        this.BingImgServiceImpl = BingImgServiceImpl;
        this.bingImgMapper = bingImgMapper;
        this.bingImgDAO = bingImgDAO;
    }

    @ApiOperation("获取必应首页图片")
    @PostMapping("/bing/{num}")
    public R<List<BingImg>> getBingImgList(@PathVariable int num) throws Exception {
        if (num > 4) {
            return R.failed("值错误");
        }
        return R.ok(bingImgDAO.getLatestByNum(num));
    }

}